if( Rails.controller == 'search' )
{
    Event.observe(window, 'load', function(){

        var handle1 = $('handle1');
        var handle2 = $('handle2');

        $('min_price').style.display = 'none'
        $('max_price').style.display = 'none'

        price_slider = new Control.Slider(['handle_wrapper1', 'handle_wrapper2'], 'track', {
            axis: 'horizontal',
            onSlide: function(v, k) {
                
                handle1.innerHTML = v[0]>=1 ? '&#8734;' : '&euro;' + t2price(v[0]);
                handle2.innerHTML = v[1]>=1 ? '&#8734;' : '&euro;' + t2price(v[1]);
                
                min = Math.min(v[0], v[1]);
                max = Math.max(v[0], v[1]);

                $('active_track').style.left  = k.translateToPx(min)
                $('active_track').style.width = k.translateToPx(max-min)
            },

            onChange: function(v, k) {
                k.options.onSlide(v, k);

                min = Math.min(v[0], v[1]);
                max = Math.max(v[0], v[1]);

                $('min_price').value = (min > 0 && min < 1) ? t2price(min) : '';
                $('max_price').value = (max > 0 && max < 1) ? t2price(max) : '';
            }
        });

        values = [
            !isNaN(parseFloat($('min_price').value)) ? price2t(parseFloat($('min_price').value)) : 0,
            !isNaN(parseFloat($('max_price').value)) ? price2t(parseFloat($('max_price').value)) : 1
        ];


        price_slider.setValue(values[0], 0);
        price_slider.setValue(values[1], 1);

    });
    
    function t2price(t)
    {
        return Math.ceil(t*100)
    }

    function price2t(price)
    {
        return Math.max(0, Math.min(price/100, 1));
    }
}


